package ooday04;

public class Test {
    public static void main(String[] args) {
       Animal[]animals=new Animal[5];
        animals[0]=new Dog("小黑",1,"黑色");
        animals[1]=new Dog("小白",2,"白色");
        animals[2]=new Fish("小金",3,"金色");
        animals[3]=new Fish("小花",4,"花色");
        animals[4]=new Chick("小灰",5,"灰色");

        for (int i = 0; i <animals.length ; i++) {
            animals[i].eat();
            animals[i].drink();

            if (animals[i]instanceof Dog){//若为DOG类型
                Dog dog=(Dog)animals[i];
                dog.swim();
            }
            if (animals[i]instanceof Chick){//若为CHICK类型
                Chick chick=(Chick)animals[i];
                chick.dance();
            }
            if (animals[i]instanceof Swim){//若为能游泳类型（实现SWIM接口）
              Swim swim=(Swim)animals[i];
              swim.swim();
            }
        }
    }
}
